<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStoreGoodsTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //商品
        Schema::create('store_goods', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('goods_name')->comment('商品名称');
            $table->string('goods_img')->comment('商品图片')->default('');
            $table->string('goods_spec')->comment('商品规格');
            $table->string('goods_number')->comment('商品库存');
            $table->decimal('goods_price',8,2)->comment('商品价格');
            $table->tinyInteger('goods_type')->comment('商品类型');
            $table->integer('level_id')->unsigned()->index('level_id')->comment('商品栏目id');
            $table->integer('hotel_id')->unsigned()->index('hotel_id')->comment('酒店外键id');
            $table->boolean('is_hot')->comment('是否热门商品');
            $table->timestamps();

            $table->foreign('level_id')
                  ->references('id')
                  ->on('store_levels')
                  ->onDelete('cascade');

            $table->foreign('hotel_id')
                  ->references('id')
                  ->on('hotels')
                  ->onDelete('cascade');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('store_goods');
    }
}
